import request from '@/utils/request'
import method from '@/utils/config'

const urlPrefix = 'crm/'

// 请求路径
const businessApi = {
  // 按条件分页查询
  listByParamsForTable: urlPrefix + 'business/listByParamsForTable',
  // 插入一条数据,返回主键
  saveHasKey: urlPrefix + 'business/saveHasKey',
  // 根据id批量删除
  deleteBatchByIds: urlPrefix + 'business/deleteBatchByIds',
  // 根据主键有选择性更新记录
  updateByPrimaryKeySelective: urlPrefix + 'business/updateByPrimaryKeySelective',
  // 根据id查询记录
  selectByPrimaryKey: urlPrefix + 'business/selectByPrimaryKey/',
  // 查询所有商机状态组
  selectType: urlPrefix + 'businessType/queryList',
  // 查询商机状态组下所有状态
  getStatusByTypeId: urlPrefix + 'businessStatus/getStatusByTypeId',
  // 查询商机下关联的产品
  listProduct: urlPrefix + 'business/listProduct',
  // 查询商机下关联的合同
  listContract: urlPrefix + 'business/listContract',
  // 查询商机下关联的联系人
  listContacts: urlPrefix + 'business/listContacts',
  // 关联联系人
  relateContacts: urlPrefix + 'business/relateContacts',
  // 解除关联联系人
  unRelateContacts: urlPrefix + 'business/unRelateContacts',
  // 修改商机负责人
  changeOwnerUser: urlPrefix + 'business/changeOwnerUser',
  // 查看商机状态
  getBusinessStatus: urlPrefix + 'business/getBusinessStatus',
  // 提升商机状态
  upgradeBusinessStatus: urlPrefix + 'business/upgradeBusinessStatus',
  // 设置首要联系人
  setImportantContacts: urlPrefix + 'business/setImportantContacts'
}

/**
 * 分页按条件查询
 * @param page 当前页数
 * @param limit 每页条数
 * @param data 条件对象
 * @returns {*}
 */
export function listByParamsForTable(queryParams) {
  return request({
    url: businessApi.listByParamsForTable,
    method: method.POST,
    data: queryParams
  })
}

/**
 * 插入一条数据,返回主键
 * @param data 要插入的数据
 * @returns {*}
 */
export function saveHasKey(data) {
  return request({
    url: businessApi.saveHasKey,
    method: method.POST,
    data
  })
}

/**
 * 根据id批量删除
 * @param ids id集合
 * @returns {*}
 */
export function deleteBatchByIds(ids) {
  return request({
    url: businessApi.deleteBatchByIds + `/${ids}`,
    method: method.DELETE
  })
}

/**
 * 根据主键有选择性更新记录
 * @param data 要更新的记录
 * @returns {*}
 */
export function updateByPrimaryKeySelective(data) {
  return request({
    url: businessApi.updateByPrimaryKeySelective,
    method: method.PUT,
    data
  })
}

/**
 * 根据id查询记录
 * @param id 查询id
 * @returns {*}
 */
export function selectByPrimaryKey(id) {
  return request({
    url: businessApi.selectByPrimaryKey,
    method: method.GET,
    params: {
      id
    }
  })
}

/**
 * 查询所有商机状态组
 * @param queryParams 多条件查询对象
 * @returns {*}
 */
export function selectType(queryParams) {
  return request({
    url: businessApi.selectType,
    method: method.POST,
    params: {
      page: queryParams.page,
      limit: queryParams.limit
    },
    data: queryParams.data
  })
}

/**
 * 查询所有商机状态组
 * @param queryParams 多条件查询对象
 * @returns {*}
 */
export function getStatusByTypeId(queryParams) {
  return request({
    url: businessApi.getStatusByTypeId,
    method: method.GET,
    params: {
      page: queryParams.page,
      limit: queryParams.limit,
      typeId: queryParams.typeId
    }
  })
}

/**
 * 查询商机下关联合同
 * @param queryParams 多条件查询对象
 * @returns {*}
 */
export function listContractFromBusiness(queryParams) {
  return request({
    url: businessApi.listContract,
    method: method.POST,
    data: {
      page: queryParams.page,
      limit: queryParams.limit,
      searchId: queryParams.searchId
    }
  })
}

/**
 * 查询商机下关联产品
 * @param queryParams 多条件查询对象
 * @returns {*}
 */
export function listProductFromBusiness(queryParams) {
  return request({
    url: businessApi.listProduct,
    method: method.POST,
    data: {
      page: queryParams.page,
      limit: queryParams.limit,
      searchId: queryParams.searchId
    }
  })
}


